package org.lq.view;

import java.awt.EventQueue;

import javax.swing.JInternalFrame;
import javax.swing.JPanel;
import javax.swing.border.TitledBorder;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;

import org.lq.data.BookDataSet;
import org.lq.entity.Book;

public class UI_ShowBook extends JInternalFrame {
	private static JTable table;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					UI_ShowBook frame = new UI_ShowBook();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public UI_ShowBook() {
		setMaximizable(true);
		setIconifiable(true);
		setClosable(true);
		setBounds(100, 100, 673, 473);
		getContentPane().setLayout(null);
		
		JPanel panel = new JPanel();
		panel.setBorder(new TitledBorder(null, "\u56FE\u4E66\u67E5\u8BE2", TitledBorder.LEADING, TitledBorder.TOP, null, null));
		panel.setBounds(10, 10, 637, 62);
		getContentPane().add(panel);
		
		JScrollPane scrollPane = new JScrollPane();
		scrollPane.setBounds(10, 89, 637, 344);
		getContentPane().add(scrollPane);
		
		table = new JTable();
		table.setModel(new DefaultTableModel(
			new Object[][] {
			},
			new String[] {
				"\u7F16\u53F7", "\u540D\u79F0", "\u4F5C\u8005", "\u7C7B\u578B", "\u63CF\u8FF0"
			}
		));
		scrollPane.setViewportView(table);
		initTable();
	}
	
	
	
	public static void initTable() {
		Book [] books = BookDataSet.getInstance().getBooks();
		DefaultTableModel dtm = (DefaultTableModel) table.getModel();
		
		int count = dtm.getRowCount();
		for (int i = 0; i < count; i++) {
			dtm.removeRow(0);
		}
		
		for (Book book : books) {
			if(book!=null) {
				dtm.addRow(new Object[] {book.getBid(),book.getBookName(),book.getAuthor().getName(),book.getBookType().getTitle(),book.getDesc()});
			}
		}
		
	}
	
	
	
	
	
	
	
	
	
	
}
